<!DOCTYPE html>
<html>
<head lang="zh-cn">
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="description" content="">
  <meta name="keywords" content="">
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <title>格悦会VIP系统（内测版）</title>
  <meta name="renderer" content="webkit">
  <!-- No Baidu Siteapp-->
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <link rel="alternate icon" type="image/png" href="i/favicon.png">
  <link rel="apple-touch-icon-precomposed" href="i/app-icon72x72@2x.png">
  <meta name="apple-mobile-web-app-title" content="AMUI React">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <link rel="stylesheet" href="dist/amazeui.touch.min.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-with-addons.min.js"></script>
</head>     
          <?php

error_reporting(E_ALL & ~(E_STRICT|E_NOTICE));

//微信API初始验证
if($_GET['echostr']){
	check_weixin_api();
	die();
}

//路由跳转
if ($_GET['a']=="getinfo"){
	
	getinfo();die();
	
}elseif($_GET['a']=="getcode"){

	getcode();die();
	
}

else{
	
	getinfo();die();
	
}




function getinfo(){
	
     $appid = 'wx7486af3dbd72e41d';
                
     $appsecret   = '1e493cc067db3cebe5382c2728b0c890';
     
     $redirect = urlencode('http://weixin.job.waijiao.org.cn/yuansheng.php?a=getcode');
     
     $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$appid."&redirect_uri=".$redirect."&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
     
     echo '<meta http-equiv="Refresh" content="0; url='.$url.'" /> ';	
	
}

function getcode(){
	
/* 		if(!$_GET['code']){
			
			echo '<meta http-equiv="Refresh" content="0; url=http://3d.yanxishe.cc/index.php">';
				
		} */
	
	    $appid = 'wx7486af3dbd72e41d';
                
        $appsecret   = '1e493cc067db3cebe5382c2728b0c890';
        
        $code = $_GET['code'];
        
        $url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$appsecret.'&code='.$code.'&grant_type=authorization_code';
        
        $data = array();
        $res = http($url, $data, 'POST', array("Content-type: text/html; charset=utf-8"));
        
        echo '<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />';
        
        $resArr = json_decode($res);
        
		$access_token = $resArr->access_token;
        $openid = $resArr->openid;
        
        
        $url = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$access_token.'&openid='.$openid.'&lang=zh_CN';
        
        $res2 =  http($url, $data, 'GET', array("Content-type: text/html; charset=utf-8"));
        
        $resArr2 = json_decode($res2);
        
        $nickname  = $resArr2->nickname;
        $pic       = $resArr2->headimgurl;
	$sex       = $resArr2->sex;
	$openid    = $resArr2->openid;
		
		
		
		
		 echo "性别：{$sex}"; 
        
         echo "昵称：{$nickname}<br> ";
		
        echo "头像：<img src='$pic' width='20%'>";
		
        echo "<hr>";
        
        print_r($res2);
		
		echo "<hr>";
		
		var_dump($resArr2);

		echo "<hr>";  
		
	
}   /* function getcode */   


function check_weixin_api(){

define(TOKEN,'weixin1234');

$timestamp = $_GET['timestamp'];
$nonce     = $_GET['nonce'];
$token     = TOKEN;

$signature = $_GET['signature'];

$tmpArr = array($timestamp,$nonce,$token);

sort($tmpArr,SORT_STRING);

$tmpStr = sha1(implode($tmpArr));

if ($tmpStr == $signature  && $_GET['echostr']){

    echo $_GET['echostr'];

}else{
    //echo '没有Echo Str ，FALSE';
      echo "FALSE";
   
}

}


/**

 * 发送HTTP请求方法

 * @param  string $url    请求URL

 * @param  array  $params 请求参数

 * @param  string $method 请求方法GET/POST

 * @return array  $data   响应数据


 */
function http($url, $params, $method = 'GET', $header = array(), $multi = false){
    $opts = array(
            CURLOPT_TIMEOUT        => 30,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => false,
            CURLOPT_HTTPHEADER     => $header
    );
    /* 根据请求类型设置特定参数 */
    switch(strtoupper($method)){
        case 'GET':
            $opts[CURLOPT_URL] = $url . '?' . http_build_query($params);
            break;
        case 'POST':
            //判断是否传输文件

            $params = $multi ? $params : http_build_query($params);

            $opts[CURLOPT_URL] = $url;
            $opts[CURLOPT_POST] = 1;
            $opts[CURLOPT_POSTFIELDS] = $params;
            break;
        default:
            throw new Exception('不支持的请求方式！');
    }
    /* 初始化并执行curl请求 */
    $ch = curl_init();
    curl_setopt_array($ch, $opts);
    $data  = curl_exec($ch);
    $error = curl_error($ch); 
    curl_close($ch);
    if($error) throw new Exception('请求发生错误：' . $error);
    return  $data;
}
?>

        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        